#include <stdio.h>
#include <stdlib.h>

#include "../utils/fsm.h"

#define LED_PADDING -1
#define LED_OFF 0
#define LED_ON 1

int led_padding_func(fsm_root_t *root, void *userdata)
{
    int on = 0;
    scanf("%d", &on);
    if (on == 0)
        return LED_OFF;
    return LED_ON;
}

int led_off_func(fsm_root_t *root, void *userdata)
{
    printf("off!\n");
    return LED_PADDING;
}

int led_on_func(fsm_root_t *root, void *userdata)
{
    printf("on!\n");
    return LED_PADDING;
}

int main(int argc, char *argv[])
{
    fsm_node_t nodes[] = {
        {LED_ON, led_on_func},
        {LED_OFF, led_off_func},
        {LED_PADDING, led_padding_func},
    };
    fsm_root_t root = {
        .exit = 0,
        .state = LED_PADDING,
        .nodes = nodes,
        .nodes_count = sizeof(nodes) / sizeof(fsm_node_t),
    };
    printf("init finish!\n");
    fsm_run(&root, NULL);
}